<template>
  <div id="medical-record">
    <div class="pant" v-if="pantShow"><span @click="back">亲属</span> / 病例</div>
    <div class="top-panel">
      <div class="top-item">
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="patient_id" label="患者身份证"></el-table-column>
      <el-table-column prop="patient_name" label="患者姓名"></el-table-column>
      <el-table-column prop="institute_name" label="机构名"></el-table-column>
      <!-- <el-table-column prop="institute_type" label="机构类型"></el-table-column> -->
      <!-- <el-table-column prop="title" label="病历主题"></el-table-column> -->
      <el-table-column fixed="right" label="操作" width="220">
        <template slot-scope="scope">
          <el-button type="text" @click="checkMedicalRecord(scope.row)" size="small">查看病历</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-panel">
      <el-pagination background layout="prev, pager, next" :total="total" @current-change="changePage"></el-pagination>
    </div>
  </div>
</template>

<script>
import { recordList } from '@/utils/data/recordList'
import { medicalRecord, ship } from '@/api';
export default {
  name: "MedicalRecord",
  data() {
    return {
      keyWord1:null,
      pantShow:false,
      tableData: [],
      total: 10,
      data: {
        cur: 1,
        shipId: null,
        institute_name: null,
        dept_name: null,
        doc_name: null,
      },
    };
  },
  created() {
    // console.log(this.$route.query.shipId);
    const shipId = this.$route.query.shipId;
    
    if (shipId) {
      this.getShipMrList();
    } else {
      this.getMedicalRecordList()
    }
  },
  methods: {
    //返回上一页
    back(){
      this.$router.go(-1);
    },
    //分页点击事件
    changePage(val) {
      this.data.cur = val;
      this.getShipMrList()
    },
    searchDepartmentByKeyWord(){
      console.log(this.keyWord1)
      let obj={
        cur: 1,
        institute_name: this.keyWord1
      }
      medicalRecord.getMedicalRecordList(obj).then(res => {
        this.tableData = res.data.data.records;
      })
    },

    getMedicalRecordList() {
      this.pantShow=false;
      medicalRecord.getMedicalRecordList(this.data).then(res => {
        this.tableData = res.data.data.records;
        this.total=res.data.data.toal;
        console.log(res)
      })
    },

    getShipMrList() {
      // this.data.cur = 2;
      this.pantShow=true;
      ship.getShipMrList(this.data).then(res => {
        // console.log(res);
        // console.log(res.data.data.records);
        this.tableData = res.data.data.records;
        this.total=res.data.data.toal;
        console.log(res.data.data.total)
        
      })
    },

    // 跳转到查看病历页面
    checkMedicalRecord(row) {
      console.log(row);
      this.$router.push({
        name: 'PersonMedicalInfo',
        query: {
          id: row.id
        }
      })
    },
  },
};
</script>

<style scope>
.pant{
  margin: 5px 10px;
}
</style>